package com.shao.tactics;

import java.util.HashMap;
import java.util.Map;

/**
 * @author PaoFu
 * @version 1.0
 * @data 2025/3/25 16:31
 */
public class Calculator {

    private static final Map<String, Operation> operationMap = new HashMap<>(8);

    static {
        operationMap.put("+", new Addition());
        operationMap.put("-", new Subtraction());
        operationMap.put("*", new Multiplication());
        operationMap.put("/", new Division());
    }

    // 操作类
    private Operation operation;

    public void setOperation(String operation) {
        this.operation = operationMap.get(operation);
    }

    public double execute(double num1, double num2) {
        return operation.calculate(num1, num2);
    }
}
